package com.shadow.baiqun.delegate.receive.adapter;

import android.support.annotation.Nullable;
import android.view.View;

import com.shadow.baiqun.R;
import com.shadow.baiqun.config.ItemField;
import com.shadow.baiqun.config.ItemType;
import com.shadow.baiqun.delegate.receive.goodscheck.GoodsCheckEntry;
import com.shadow.baiqun.event.ModifyPreGoodsEvent;
import com.shadow.ui.recycler.MultipleItemEntity;
import com.shadow.ui.recycler.MultipleRecyclerAdapter;
import com.shadow.ui.recycler.MultipleViewHolder;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * @author zy
 *         on 2018/5/27
 */
public class CheckAdapter extends MultipleRecyclerAdapter {


    public CheckAdapter(@Nullable List<MultipleItemEntity> data) {
        super(data);
        addItemType(ItemType.CAN_EDIT, R.layout.item_check);
        addItemType(ItemType.CAN_NOT_EDIT, R.layout.item_check_un_edit);
    }

    @Override
    protected void convert(final MultipleViewHolder helper, final MultipleItemEntity item) {
        final GoodsCheckEntry goodsCheckEntry = item.getField(ItemField.ITEM_OBJ);
        helper.setText(R.id.et_part_name, goodsCheckEntry.getPrepgoodsCCptname());
        helper.setText(R.id.et_part_code, goodsCheckEntry.getPrepgoodsCCptcode());
        helper.setText(R.id.et_supplier_name, goodsCheckEntry.getPrepgoodsCSupname());
        helper.setText(R.id.et_supplier_code, goodsCheckEntry.getPrepgoodsCSupcode());
        helper.setText(R.id.et_package_number, goodsCheckEntry.getPrepgoodsCNum());
        helper.setText(R.id.et_part_number, goodsCheckEntry.getPrepgoodsCTotal());
        helper.setText(R.id.et_remark, goodsCheckEntry.getPrepgoodsCRemark());
        helper.setText(R.id.et_send_time, goodsCheckEntry.getPrepgoodsCSendtime());
        helper.setText(R.id.et_clint_name, goodsCheckEntry.getPrepgoodsCCusbatch());
        helper.setText(R.id.et_baiqun_group, goodsCheckEntry.getPrepgoodsCBatch());
        String status = goodsCheckEntry.getPrepgoodsCStatus();
        if ("0".equals(status)) {
            status = "未核对";
        } else if ("1".equals(status)) {
            status = "已核对";
        } else {
            status = "修改过";
        }
        helper.setText(R.id.et_status, status);
        helper.setText(R.id.tv_position, (helper.getLayoutPosition() + 1) + "/" + getItemCount());
        switch (item.getItemType()) {
            case ItemType.CAN_EDIT:
                helper.getView(R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

//                        String partCode = ((AppCompatEditText) helper.
//                                getView(R.id.et_part_code)).getText().toString();
//                        String packageNumber = ((AppCompatEditText) helper.
//                                getView(R.id.et_package_number)).getText().toString();
//                        String supplierName = ((AppCompatEditText) helper.
//                                getView(R.id.et_supplier_name)).getText().toString();
//                        String supplierCode = ((AppCompatEditText) helper.
//                                getView(R.id.et_supplier_code)).getText().toString();
//                        String partNumber = ((AppCompatEditText) helper.
//                                getView(R.id.et_part_number)).getText().toString();
//                        String sendTime = ((AppCompatEditText) helper.
//                                getView(R.id.et_send_time)).getText().toString();
//                        String group = ((AppCompatEditText) helper.
//                                getView(R.id.et_baiqun_group)).getText().toString();
//                        goodsCheckEntry.setPrepgoodsCCptcode(partCode);
//                        goodsCheckEntry.setPrepgoodsCNum(packageNumber);
//                        goodsCheckEntry.setPrepgoodsCSupname(supplierName);
//                        goodsCheckEntry.setPrepgoodsCSupcode(supplierCode);
//                        goodsCheckEntry.setPrepgoodsCTotal(partNumber);
//                        goodsCheckEntry.setPrepgoodsCAddtime(sendTime);
//                        goodsCheckEntry.setPrepgoodsCBatch(group);
                        EventBus.getDefault().post(new ModifyPreGoodsEvent(goodsCheckEntry,
                                getParentPosition(item)));

                    }
                });
                break;
            case ItemType.CAN_NOT_EDIT:
                break;
        }

    }

}
